package org.example.jdbc_study.web;

import org.example.jdbc_study.domain.dto.MyUserDto;
import org.example.jdbc_study.domain.vo.MyUserVo;
import org.example.jdbc_study.service.MyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户Controller
 *
 * @author 欧阳劲驰
 * @since 0.0.1
 */
@Controller
@RequestMapping("myUser")
public class MyUserController {
    @Autowired
    MyUserService myUserService;

    /**
     * 页面
     * @return 页面地址
     */
    @GetMapping("")
    public String index() {
        return "myUser";
    }

    /**
     * 添加用户
     *
     * @param myUserVo 用户Vo
     * @return 添加状态
     */
    @PostMapping("addMyUser")
    @ResponseBody
    public Boolean addMyUser(@RequestBody MyUserVo myUserVo) {
        return myUserService.addMyUser(myUserVo);
    }

    /**
     * 获取用户
     *
     * @return 用户集合
     */
    @GetMapping("getMyUser")
    @ResponseBody
    public List<MyUserDto> getMyUser() {
        return myUserService.getMyUser();
    }

    /**
     * 修改用户
     *
     * @param myUserVo 用户Vo
     * @return 用户集合
     */
    @PostMapping("editMyUser")
    @ResponseBody
    public Boolean editMyUser(@RequestBody MyUserVo myUserVo) {
        return myUserService.editMyUser(myUserVo);
    }

    /**
     * 删除用户
     *
     * @param id id
     * @return 用户集合
     */
    @GetMapping("delMyUser")
    @ResponseBody
    public Boolean delMyUser(Long id) {
        return myUserService.delMyUser(id);
    }
}
